//
//  NoDataView.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/25.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "NoDataView.h"

static NoDataView *noDataView = nil;

@implementation NoDataView

+ (instancetype)shareInstance{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        noDataView = [[NoDataView alloc] init];
    });
    
    
    noDataView.noticeLabel.text = @"暂无数据";
    
    return noDataView;
}

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = CSClearColor;
        
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"暂无任何内容"];
        [self addSubview:imageView];
        self.imageView = imageView;
        
        /**
         提示Label
         */
        UILabel *noticeLabel = [[UILabel alloc] init];
        noticeLabel.text = @"暂无数据";
        noticeLabel.font = MidFont;
        noticeLabel.textColor = TextColor1;
        [self addSubview:noticeLabel];
        self.noticeLabel = noticeLabel;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self);
        
        make.bottom.mas_equalTo(self.mas_centerY);
    }];
    
    /**
     提示Label
     */
    [self.noticeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self);
        
        make.top.mas_equalTo(self.imageView.mas_bottom).offset(15);
    }];
}


/**
 显示View
 */
- (void)showInView:(UIView *)view{
    
    [view insertSubview:self atIndex:0];
    
    [view bringSubviewToFront:self];
    
    [self mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(view);
    }];
}

/**
 显示View
 */
- (void)showFrontInView:(UIView *)view{
    
    [view insertSubview:self atIndex:0];
    
    [self mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(view);
    }];
}


- (void)showTopInView:(UIView *)view{
    
    [view insertSubview:self atIndex:0];
    
    [self mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(view);
        
        make.centerY.mas_equalTo(view).offset(-50);
    }];
}

- (void)hideInView:(UIView *)view{
    
    [self removeFromSuperview];
}

@end
